
#if defined(WIN32) || defined(WIN64)
#pragma unmanaged
#endif

#include <Liberty3D/Engine/GLException.h>

using namespace Liberty::Engine;

#ifndef LY_EOL
#ifdef WIN32
#define LY_EOL "\r\n"
#else
#define LY_EOL "\n"
#endif
#endif

#define LY_FL_SIGNATURE  "File: %s" LY_EOL "Line: %u"
#define LY_FFL_SIGNATURE "Function: %s" LY_EOL LY_FL_SIGNATURE

#ifndef WIN32
#define sprintf_s snprintf
#endif

GLException::GLException(GLenum err, const char* what) : std::runtime_error(what), _err(err) {
}

void GLException::raiseEnterFunction(GLenum err, const char* function, const char* file, unsigned int line) {
    char s[512];

    sprintf_s(s, 512, "Unhandled error detected entering function %s" LY_EOL LY_EOL LY_FL_SIGNATURE, function, file, line);
    throw GLException(err, s);
}

void GLException::raiseCallFunction(GLenum err, const char* glFunction, const char* function, const char* file, unsigned int line) {
    char s[512];

    sprintf_s(s, 512, "Unhandled error detected calling %s" LY_EOL LY_EOL LY_FFL_SIGNATURE, glFunction, function, file, line);
    throw GLException(err, s);
}
